//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package common;

import com.google.gson.JsonArray;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class RoadsideShop {
    private final int slotCount;
    private final List<RoadsideShopSlot> slots;
    private boolean printNotEmptySlotsOnly = false;

    public RoadsideShop(int numSlots) {
        this.slotCount = numSlots;
        this.slots = new ArrayList();
    }

    public void initEmptyShop() {
        for(int i = 0; i < this.slotCount; ++i) {
            this.slots.add(new RoadsideShopSlot(i));
        }

    }

    public void decode(ByteStream stream) {
        for(int i = 0; i < this.slotCount; ++i) {
            RoadsideShopSlot s = new RoadsideShopSlot(i);
            s.decode(stream);
            this.slots.add(s);
        }

    }

    public RoadsideShopSlot getSlot(int index) {
        return index < this.slotCount?(RoadsideShopSlot)this.slots.get(index):null;
    }

    public int maxSlot() {
        return this.slotCount;
    }

    public void setPrintNotEmptySlots(boolean action) {
        this.printNotEmptySlotsOnly = action;
    }

    public JsonArray getAsJsonArray() {
        JsonArray jSlots = new JsonArray();
        Iterator var3 = this.slots.iterator();

        while(var3.hasNext()) {
            RoadsideShopSlot s = (RoadsideShopSlot)var3.next();
            jSlots.add(s.getAsJsonObject());
        }

        return jSlots;
    }

    public String toString() {
        String val = "Roadside Shop: " + this.slotCount + " slots\n";
        Iterator var3 = this.slots.iterator();

        while(true) {
            RoadsideShopSlot s;
            do {
                if(!var3.hasNext()) {
                    return val;
                }

                s = (RoadsideShopSlot)var3.next();
            } while(this.printNotEmptySlotsOnly && !(this.printNotEmptySlotsOnly & !s.isSlotEmpty()));

            val = val + "     " + s + "\n";
        }
    }
}
